package com.prdiot.poetry.service;

import com.prdiot.poetry.dao.MingjuRepository;
import com.prdiot.poetry.dao.TagsRepository;
import com.prdiot.poetry.domains.Mingju;
import com.prdiot.poetry.domains.Poems;
import com.prdiot.poetry.domains.Tags;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Service
public class MingjuService {

    @Autowired
    MingjuRepository mingjuRepository;

    //获取名句主题分类
    public List<String> getMingjuTheme(){
//        mingjuRepository.getMingjuTheme();
        return mingjuRepository.getMingjuTheme();
    }

    //随机获取
    public List<Mingju> getRandMingju() {
        return mingjuRepository.getRandMingju();
    }

    public Page<Mingju> searchByTheme(String theme, Pageable pageable){
        return  mingjuRepository.searchByTheme(theme,pageable);
    }

    public Page<Mingju> getMingjuList(Pageable pageable){
        return  mingjuRepository.getMingjuList(pageable);
    }


    public Mingju findByCode(String code){
        Optional<Mingju> mingjuOptional = mingjuRepository.findByCode(code);
        if (mingjuOptional.isPresent()){
            return  mingjuOptional.get();
        }
        return null;
    }
}
